/**
 * 积分管理
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/29
 */
var self = memberInfo = number = '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	
	self = plus.webview.currentWebview();  
	
	memberInfo = plus.storage.getItem('memberInfo');
	
	memberInfo = $.parseJSON(memberInfo);
	
	//前往提现页面
   	$('.withdrawals').on('click' , function(){
   		plus.nativeUI.showWaiting('跳转中...');
		var me_jf_tx = plus.webview.create('me-jf-tx.html', 'me_jf_tx', {}, {
			page : self.id,
			uid : memberInfo.aid,
			number : number,
			nickname : memberInfo.nickname
		});
		me_jf_tx.addEventListener('loaded', function (){   
			me_jf_tx.show('pop-in');
			plus.nativeUI.closeWaiting();''
		})	
   	})
	
	//获取积分数据 
	plus.nativeUI.showWaiting('获取中...');
	$.ajax({
		type:"post",
		url:apiRoot +'/Home/Member/myIntegral/',
		data : {
			uid : memberInfo.aid 
		},
		dataType :'json', 
		success : function(data){
			plus.nativeUI.closeWaiting();
			if(data){
				number = data.total_integral;
				$('.total').text(number)
				if(data.integral_history){
					$.each(data.integral_history, function(k,v) {
						var html = '<div class="table-view-cell background-w table-view line-h-28 bar-buttom">';
							html += '<span class="">'+v.addtime+'</span><li><span class=" color-c font-14">'+v.type;
							if(v.name){
								html += "&nbsp;&lt;&lt;"+(v.name).substr(0,10)+"&gt;&gt;";
							}
							html += '</span><span class="color-zx-2 mui-pull-right">'+((v.tid == 42 || v.tid == '-1' || v.type == '用户的差评' ) ? '-' : '+')+v.number+'</span></li></div>';
						$('.lists').append(html);
					});
				}
			}
		},
		error : function(e){
			plus.nativeUI.closeWaiting();
			toast('连接超时,请检查网络');
		}
	});
}



function addHistory(price){
	$('.total').text(parseInt($('.total').text()) + (parseInt(price) * 10))
	var html = '<div class="table-view-cell background-w table-view line-h-28 bar-buttom">';
	    html += '<span class="">刚刚</span><li><span class=" color-c font-14">充值金额 '+price+' 元</span><span class="color-zx-2 mui-pull-right">+'+(parseInt(price) * 10)+'</span></li></div>';
	$('.lists').prepend(html);
}

//window.addEventListener('add_history',function(event){
// 
//});
